package com.qs.education.controllers;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qs.education.bean.api.PageBean;
import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.entity.EducationQuestion;
import com.qs.education.bean.entity.EducationSMS;
import com.qs.education.bean.enums.ResponseStatus;
import com.qs.education.bean.utils.JsonUtil;
import com.qs.education.service.IQuestionAPIService;
import com.qs.education.service.ISMSAPIService;

/**
 * @class QuestionController
 * @author Jason
 * @description
 * @date Nov 22, 2018 10:40:45 AM
 */
@RestController
@RequestMapping("/question")
public class QuestionController {

	@Autowired
	private IQuestionAPIService iQuestionAPIService;
	
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @Description 查询符合条件的题目信息
	 * @author Jason
	 * @date Nov 22, 2018
	 * @param request
	 * @param question
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/getQuestionListAPI")
	public PageBean getQuestionList(HttpServletRequest request,String question,Integer currentPage,Integer pageSize) {
		
		log.info("api SMS 端 Controller  getQuestionListAPI ");
		EducationQuestion educationQuestion = (EducationQuestion) JsonUtil.jsonToBean(question, EducationQuestion.class);
		PageBean response = new PageBean();
		response.setToken(response.getToken(request));
		response = iQuestionAPIService.getQuestionList(educationQuestion,currentPage,pageSize);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		
		return response;
	}
	
	/**
	 * @Description 根据ID删除SMS
	 * @author Jason
	 * @date Nov 22, 2018
	 * @param request
	 * @param Id
	 * @return
	 */
	@RequestMapping("/deleteQuestionByIdAPI")
	public ResponseBean deleteQuestionById(HttpServletRequest request,Integer Id) {
		
		log.info("api Question 端 Controller  deleteQuestionById ");
		ResponseBean response = new ResponseBean();
		response.setToken(response.getToken(request));
		Boolean result = iQuestionAPIService.deleteQuestionById(Id);
		if (result) {
			response.setStatus(ResponseStatus.SUCCESS.toString());
		} else {
			response.setStatus(ResponseStatus.FAILED.toString());
		}
		
		return response;
	}
}
